package com.rz.admin.controller;

import com.rz.core.kit.RespKit;
import com.rz.core.resp.ResultResp;
import com.rz.admin.entity.Consumer;
import com.rz.admin.service.IConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author maweiyue
 * @Date 2019/07/01
 * @Description 客户管理
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Autowired
    private IConsumerService consumerService;

    @PostMapping("/getPage")
    public ResultResp getPage(@RequestBody Consumer consumer){
        return RespKit.success(this.consumerService.getPage(consumer));
    }

    @PostMapping("/save")
    public ResultResp save(@RequestBody Consumer consumer){
        return RespKit.success(this.consumerService.onSave(consumer));
    }

    @PostMapping("/delete/{id}")
    public ResultResp delete(@PathVariable Integer id){
        return RespKit.success(this.consumerService.delete(id));
    }

    /**
     * 获取组织机构树
     * @param mngId 当前系统操作用户id
     * @return
     */
    @PostMapping("/listConsumerTree/{mngId}")
    public ResultResp listOrgTree(@PathVariable Integer mngId){
        return RespKit.success(this.consumerService.listConsumerTree(mngId));
    }
    /**
     * 获取指定单位的下级单位（不包括自身）
     * @param consumerId 指定客户id
     * @return
     */
    @PostMapping("/listChildren/{consumerId}")
    public ResultResp listChildren(@PathVariable Integer consumerId){
        return RespKit.success(this.consumerService.listChildren(consumerId));
    }
}
